﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GSLMS.Core;
using GSLMS.Entity.Enum;
using GSLMS.Entity;

namespace GSLMS.WebAPP.Areas.DianDang.Controllers.FKApply.Loaning
{
    public class LoaningController : AdminBaseController
    {
        //
        // GET: /DianDang/Loaning/

        public ActionResult Index(FormCollection form)
        {
            ViewData["LoanStatus"] = EnumHelper.ToSelectList<ApplyEnum.ContractLoanStatus>();
            var searchParma = SearchPara<TB_LOAN_CONTRACT>(form, new TB_LOAN_CONTRACT() { SIGNDATE = DateTime.Now.AddMonths(-1), SIGNDATE_END = DateTime.Now });
            var list = serviceLoanContract.GetList(searchParma); //new List<TB_LOAN_CONTRACT>() { new TB_LOAN_CONTRACT() { ID = 1, CUSTNAME = "DDDDDDDD" } };//
            ViewData["RowCount"] = searchParma.RowCount;

            return View(list);
        }

        //
        // GET: /DianDang/Loaning/Create

        public ActionResult Create(int? id)
        {
            ViewData["LendorCorp"] = base.GetListFromDict("");
            ViewData["FinalApprover"] = base.GetListFromDict("");
            var model = new TB_LOAN_CONTRACT();
            if (id.HasValue && id > 0)
            {
                //model = serviceLoanContract.GetByID(id.Value);
                model = new TB_LOAN_CONTRACT() { ID = 1, CUSTNAME = "DDDDDDDD" };
            }
            return View(model);
        }

        //
        // POST: /DianDang/Loaning/Create

        [HttpPost]
        public string Create(FormCollection collection)
        {
            string result = string.Empty;
            try
            {
                var model = new TB_LOAN_CONTRACT();
                TryUpdateModel(model, collection);
                bool isSumbit = false;
                if (isSumbit)
                { result = AjaxResultSucess; }
                else
                { result = AjaxResultFail; }
            }
            catch (Exception ex)
            {
                base.ExceptionHand(ex);
                result = AjaxResultFail;
            }

            return "{" + result + "}";
        }
        public ActionResult BackTo(int? id)
        {
            ViewData["ProID"] = id;
            var model = new TB_LOAN_CONTRACT();
            //if (id.HasValue && id > 0)
            //{
            //    model = serviceLoanContract.GetByID(id.Value);
            //}
            return View(model);
        }

        [HttpPost]
        public string BackTo(FormCollection collection)
        {
            string result = string.Empty;
            try
            {
                bool isSumbit = false;
                if (isSumbit)
                { result = AjaxResultSucess; }
                else
                { result = AjaxResultFail; }
            }
            catch (Exception ex)
            {
                base.ExceptionHand(ex);
                result = AjaxResultFail;
            }

            return "{" + result + "}";
        }
    }
}
